<?php

class SchoolsController extends AppController{
	var $name = 'Schools';
	var $helpers = array('javascript','form','html'); 
	var $uses = array('Campus','School');
	//　AuthComponentの宣言
	var $components = array('Session','RequestHandler','NaturalLanguage','TwitterUser');
	var $consumer_key = "si2UvZAvFqJULHPSReXjA";
	var $consumer_secret = "qn4YEDOFUPYTwWkexlk2SdDYcW7zAvRaPNSR5GJ5k";
	var $datahash = array();
	var $theme = "jquery-mobile";
	
	function beforeFilter() {
		///Ajaxの共通処理
		//アクションにajaxが入っていたら実行
		if( $this->RequestHandler->isAjax() && strstr($this->action,'ajax')){
			//jquery-mobileはすべてajaxなので例外も入れてやる
			Configure::write('debug', 0);
			$this->layout = "";
			$this->autoRender = false;
			$this->RequestHandler->setContent('json');
			$this->RequestHandler->respondAs('application/json; charset=UTF-8');
		}else{
			if( strstr($this->action,'ajax') ){
				$this->redirect('../users/index/');
			}
		}
	}
	
	function beforeRender(){
		$this->set('datahash',$this->datahash);
		parent::beforeRender();
	}
	
	/*
	 * 検索ダイアログ 
	 */
	function search_dialog(){
		$this->layout = "dialog";//レイアウトをダイアログに
		if(!empty($this->data['School']['query'])){
			$query = $this->data['School']['query'];
			$query = str_replace("　", " ", $query);		//全角スペースを半角に
			$words = explode(" ", $query);
			$this->datahash['queryResult'] = $this->School->search($words, 0, 100);
		}
	}
	
	function ajax_searchSchools(){
		
	}
}
?>